#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<string.h>
#define NUM 32
#define LEN 1024
int main()
{
  char cmd[LEN];
  char* myarg[NUM];
  while(1)
  {   
   printf("[tzc@VM-0-5-centos shell]!");
                        //最大大小
   //char* fgets(char* s,int size,FILE * stream);
   fgets(cmd,LEN,stdin);
   cmd[strlen(cmd)-1]='\0';
   myarg[0]=strtok(cmd," ");
   int i=1;
   while(myarg[i]=strtok(NULL," "))
   {
     i++;
   }
   pid_t id =fork();
   if(id==0)
   {
     //子进程
     execvp(myarg[0],myarg);
     exit(3);
   }
   else
   {
      //父进程
      int status=0;
      pid_t ret=waitpid(id,&status,0);
      if(ret>0)
      {
        printf("exit code: %d\n",WEXITSTATUS(status));
      }
   }
    
  }

  return 0;
}
